package com.oceansoft.mobile.biz.front.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.biz.api.entity.Member;
import com.oceansoft.mobile.biz.api.webservice.TrafficVehicleService;
import com.oceansoft.mobile.biz.front.entity.AppPlugins_api;
import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.dao.ICommonDao;
import com.oceansoft.mobile.common.util.*;
import com.oceansoft.mobile.weixin.service.WechatService;
import com.oceansoft.mobile.weixin.util.SignUtil;
import com.oceansoft.mobile.weixin.util.WeixinUtil;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/1/20.
 */
@Controller
@RequestMapping("app/wx")
public class AppController {

	@Resource
	private WechatService wechatService;

	@Resource
	private ICommonDao commonDao;
	private TrafficVehicleService tvs;
	/*
	 * private static final Map<String,String> stateMap = new HashMap<String,
	 * String>();
	 * 
	 * static{ stateMap.put("0", Constant.local +
	 * "static/weixin/html/item_detail6.html");//申请门牌 stateMap.put("1",
	 * Constant.local + "micro/weixin/twowfw");//申请门牌 }
	 */

	@ResponseBody
	@RequestMapping(value = "getAppPlugins", method = RequestMethod.GET)
	public Result getAppPlugins(HttpServletRequest request) {
		String cate = request.getParameter("cate");
		String whereSQL = "";
		if (StringUtils.isEmpty(cate) || "0".equals(cate)) {
		} else {
			whereSQL = " and cate='" + cate + "'";
		}
		Result r = null;
		String key = "AppPlugins_api_" + cate;
		if (CacheBaseService.getInstance().exists(key)) {
			r = CacheBaseService.getInstance().getObject(key, Result.class);
		} else {
			List<AppPlugins_api> list = commonDao.loadList(
					"select * from t_app_plugins where state=1 " + whereSQL
							+ " order by ordernum",
					ParameterizedBeanPropertyRowMapper
							.newInstance(AppPlugins_api.class));
			r = new Result();
			r.setData(list);// cate: 1(微服务) 2(微警情) 3(微应用) orderNum:排序字段
			CacheBaseService.getInstance().cache(key, r, 1f);
		}
		// System.out.println(JSONObject.toJSON(r));
		return r;
	}



	@ResponseBody
	@RequestMapping(value = "getUserInfo")
	public Result getUserInfo(HttpServletRequest request) {
		Result result = new Result();
		String openId = request.getParameter("openId");
		if (StringUtils.isEmpty(openId)) {
			return new Result(false);
		}
		JSONObject json = JSONObject
				.parseObject("{ \"OpenId\":\"" + openId
						+ "\",  \"UserSource\":3}");
		String a = "";
		try {
			a = HttpClientUtil.post(Constant.host5 + WeixinUtil.USERAUTH_URL,
					json);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		JSONObject jsona = JSONObject
				.parseObject(a);
		// String openId = (String)sessiion.getAttribute("openId");
		/**
		 * 如果是绑定用户，存session，把用户信息放到session里
		 */
		Member member = new Member();
		if ((Boolean) jsona.get("succ")) {
			try {
				member = WeixinUtil.SetMember(JSONObject
						.parseObject(jsona.get("data").toString()));
			} catch (Exception e) {
				e.printStackTrace();
			}
			member.setOpenId(openId);
			return new Result(member);
		}
		result.setSucc(false);
		result.setData(json);
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "abcTest")
	public JSONObject abcTest(HttpServletRequest request) {
		String url = request.getParameter("url");
		String jsapiTicket = wechatService.getJsapiTicket();
		JSONObject json = SignUtil.getSignature(jsapiTicket, url);
		return json;
	}

	/**
	 * 注销用户，删除网厅的绑定关系,太仓
	 * 
	 * @param request
	 * @return
	 * @throws IllegalArgumentException
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "userszx")
	public Result userszx(HttpServletRequest request)
			throws IllegalArgumentException, Exception {
		String	openId = request.getParameter("openId");
		if(StringUtils.isEmpty(openId))
		{
			return new Result(Result.FAILURE, "无法获取openId,完成注销！");
		}
		request.getSession().setAttribute("openId", openId);
		boolean b = WeixinUtil.checkIsLoginUser(request);
		Member member = new Member();
		if (b) {
			member = (Member) request.getSession().getAttribute(
					Constant.SESSION_USER);
		}
		if (null == member) {
			return new Result(600, "您当前未登陆,请返回登陆！");
		}
		String url = Constant.host5 + "api/Users/Userszx?userguid="
				+ member.getGuid() + "&openid=" + openId;
		Result result = JSONObject.parseObject((HttpClientUtil.doGet(url)),
				Result.class);
		if (result.isSucc()) {
			request.getSession().removeAttribute(Constant.SESSION_USER);
		}
		request.getSession().removeAttribute(openId);
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "vehicle/{hphm}/{vin}")
	public JSONObject queryVehicle(HttpServletRequest request,
			@PathVariable("hphm") String hphm,
			@PathVariable("vin") String vin) {
		if(StringUtils.isNotEmpty(hphm)&&hphm.startsWith("苏"))
		{
			hphm = hphm.substring(1,hphm.length()-1);
		}
		tvs = TrafficVehicleService.getInstance();
		String info =  "";
		try{
			info = tvs.getVehicleiInfo(hphm, vin);
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		//{"msg":"获取机动车基本信息成功","result":true,"vehicle":{"BXZZRQ":"2017-04-28T00:00:00","CCDJRQ":"2016-05-03T12:59:47","CCRQ":"2016-07-06T17:37:35.5588872+08:00","CLSBDH":"YV1MV2923G2334146","CWKC":0,"CWKG":0,"CWKK":0,"DYBJ_NAME":"已抵押","GBTHPS":0,"GL":0.0,"HDZK":0,"HDZZL":0,"HPHM":"E9GT78","HPZK":0,"HPZL_NAME":"小型汽车","HXNBCD":0,"HXNBGD":0,"HXNBKD":0,"PL":0,"QPZK":0,"QZBFQZ":"2016-07-06T17:37:35.5588872+08:00","SYR":"朱伟家","YXQZ":"2018-05-31T00:00:00","ZBZL":0,"ZQYZL":0,"ZS":0,"ZT":"A","ZT_NAME":"正常","ZZL":0}} 
		JSONObject json =  JSONObject.parseObject(info);
		String msg = (String)json.get("msg");
		System.out.println("msg=="+msg);
		return json;
	}
	
	@ResponseBody
	@RequestMapping(value = "surveil/{hphm}/{vin}")
	public JSONObject querySurveil(HttpServletRequest request,
			@PathVariable("hphm") String hphm,
			@PathVariable("vin") String vin) {
		if(StringUtils.isNotEmpty(hphm)&&hphm.startsWith("苏"))
		{
			hphm = hphm.substring(1,hphm.length());
			hphm = hphm.toUpperCase();
		}
		vin = vin.toUpperCase();
		String key = "traffic:"+hphm+"_"+vin;
		JSONObject json = new JSONObject();
		//数据缓存
		if (CacheBaseService.getInstance().exists(key)) { 
			json = CacheBaseService.getInstance().getObject(key,
					JSONObject.class);
			//System.out.println("缓存");
		} 
		else
		{
			//{"result":true,"msg":"获取未处理的机动车交通违法信息成功","vioSurveil":[{"XH":"3213237901617354","HPZL":null,"HPHM":null,"CLSBDH":null,"CJJGMC":"泗阳大队","WFSJ":"2016-04-22T10:45:00","WFDZ":"青泗线（245省道）131公里900米","WFXW":"驾驶中型以上载客载货汽车、危险物品运输车辆以外的其他机动车行驶超过规定时速10%未达20%的","CLBJ":null,"JKBJ":null,"WFJFS":0,"FKJE":"50","ZT":"未处理未交款","WFJFS1":"3"},{"XH":"3205080011612849","HPZL":null,"HPHM":null,"CLSBDH":null,"CJJGMC":"苏州市城市管理执法局","WFSJ":"2016-05-12T09:39:00","WFDZ":"虎阜路虎阜路999号虎丘婚纱城门口人行道板上","WFXW":"机动车违反规定停放、临时停车妨碍其他车辆、行人通行的，驾驶人不在现场的","CLBJ":null,"JKBJ":null,"WFJFS":0,"FKJE":"50","ZT":"未处理未交款","WFJFS1":"0"}]}
			tvs = TrafficVehicleService.getInstance();
			try{
				String info = tvs.getVioSurveil("02", hphm, vin);
				json =  JSONObject.parseObject(info);
				//获取图片
				JSONArray wzs = (JSONArray) json.get("vioSurveil");
				/*for (Object object : wzs) {
					String xh = (String)((JSONObject)object).get("XH");
					//System.out.println(xh);
					String photo = tvs.getPhotoByXH(xh);
					JSONObject ps =   JSONObject.parseObject(photo);
					if((Boolean)ps.get("result"))
					{
						//System.out.println(ps.get("msg"));
						((JSONObject)object).put("photo", ps.get("photo"));
					}
				}*/
				CacheBaseService.getInstance().cache(key,json,1f);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
//		String msg = (String)json.get("msg");
		//System.out.println("msg=="+msg);
		return json;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "violation/{jszh}/{dabh}")
	public JSONObject getViolation(HttpServletRequest request,
			@PathVariable("jszh") String jszh,
			@PathVariable("dabh") String dabh) {
		if(StringUtils.isNotEmpty(jszh))
		{
			jszh = jszh.toUpperCase();
		}
		String key = "traffic:"+jszh+"_"+dabh;
		JSONObject json = new JSONObject();
		//数据缓存
		if (CacheBaseService.getInstance().exists(key)) { 
			json = CacheBaseService.getInstance().getObject(key,
					JSONObject.class);
			//System.out.println("缓存");
		} 
		else
		{
			//{"msg":"获取驾驶证交通违法信息成功","result":true,"violation":[{"CFZL":"罚款","CLJGMC":"常熟市公安局交通巡逻警察大队车管所","CLSJ":"2012-07-09T13:17:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟市公安局交通巡逻警察大队车管所","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320581170045263","JKRQ":"2012-07-09T00:00:00","WFDZ":"204国道老线895公里","WFJFS":3,"WFNR":"机动车未按照规定期限进行安全技术检验","WFSJ":"2012-07-09T13:17:00","WFXW":"1340","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓大队城厢中队","CLSJ":"2011-11-04T12:20:00","FKJE":50,"FLAG":0,"FXJGMC":"太仓大队城厢中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585199554534","JKRQ":"2012-05-14T00:00:00","WFDZ":"浏昆线（339省道）","WFJFS":0,"WFNR":"机动车驾驶人有其它违反道路通行规定的行为的","WFSJ":"2011-11-04T12:20:00","WFXW":"7005","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓大队南郊中队","CLSJ":"2011-11-03T07:58:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓大队南郊中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585199558186","JKRQ":"2012-05-14T00:00:00","WFDZ":"烟沪线（204国道）","WFJFS":0,"WFNR":"公路客运车辆以外的载客汽车违反规定载货的","WFSJ":"2011-11-03T07:58:00","WFXW":"1092","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"相城大队渭塘中队","CLSJ":"2011-09-30T16:03:00","FKJE":50,"FLAG":0,"FXJGMC":"相城大队渭塘中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320507199252608","JKRQ":"2012-05-14T00:00:00","WFDZ":"S227渭塘段","WFJFS":1,"WFNR":"上道路行驶的机动车未放置保险标志的","WFSJ":"2011-09-30T16:03:00","WFXW":"1108","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队浏河中队","CLSJ":"2010-12-21T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓市交巡警大队浏河中队","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585167427187","JKRQ":"2010-12-21T00:00:00","WFDZ":"338省道","WFJFS":0,"WFNR":"公路客运车辆以外的载客汽车违反规定载货的","WFSJ":"2010-12-21T13:33:04","WFXW":"1092","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队秩序科","CLSJ":"2010-11-17T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"太仓市交巡警大队秩序科","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585068040737","JKRQ":"2010-11-17T00:00:00","WFDZ":"900600000000","WFJFS":0,"WFNR":"机动车违反规定停放、临时停车，妨碍其它车辆、行人通行，驾驶人不在现场的","WFSJ":"2010-10-25T08:27:14","WFXW":"10391","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627546","JKRQ":"2010-06-29T00:00:00","WFDZ":"162220000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速20%以上未达50%的","WFSJ":"2010-04-25T12:33:21","WFXW":"13033","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627545","JKRQ":"2010-06-29T00:00:00","WFDZ":"150860000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速20%以上未达50%的","WFSJ":"2010-03-25T15:23:23","WFXW":"13033","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"太仓市交巡警大队秩序科","CLSJ":"2010-03-10T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"太仓市交巡警大队秩序科","HPHM":"苏EC6P10","HPZL":"小型汽车","JDSBH":"320585068040024","JKRQ":"2010-03-10T00:00:00","WFDZ":"900570000000","WFJFS":0,"WFNR":"机动车通过有灯控路口时，不按所需行进方向驶入导向车道的","WFSJ":"2009-12-11T15:01:30","WFXW":"1208","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队","CLSJ":"2010-06-29T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏ETJ356","HPZL":"小型汽车","JDSBH":"320581151627544","JKRQ":"2010-06-29T00:00:00","WFDZ":"153170000000","WFJFS":0,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2009-10-08T11:35:23","WFXW":"13032","XXLY":"电子监控违法","ZT":"已交款"},{"CFZL":"警告","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-09-28T08:46:16","FKJE":0,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EXR753","HPZL":"普通摩托车","JDSBH":"320581199415458","WFDZ":"205省道","WFJFS":0,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2009-09-28T08:45:00","WFXW":"1207","XXLY":"现场处罚","ZT":"无需交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-03-19T08:54:23","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EXR753","HPZL":"普通摩托车","JDSBH":"320581051710121","JKRQ":"2009-03-19T08:54:23","WFDZ":"205省道","WFJFS":0,"WFNR":"上道路行驶的机动车未按规定放置检验合格标志","WFSJ":"2009-03-19T07:10:00","WFXW":"1071","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队辛庄中队","CLSJ":"2009-07-01T14:49:41","FKJE":200,"FLAG":0,"FXJGMC":"常熟市交巡警大队辛庄中队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581151002632","JKRQ":"2009-07-01T14:49:41","WFDZ":"205省道","WFJFS":0,"WFNR":"驾驶未经检验合格的机动车","WFSJ":"2008-03-20T07:10:00","WFXW":"7002","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队海虞中队","CLSJ":"2007-03-13T10:16:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队海虞中队","HPHM":"苏EE8709","HPZL":"小型汽车","JDSBH":"320581031625521","JKRQ":"2007-03-13T10:16:00","WFDZ":"谢桥镇","WFJFS":0,"WFSJ":"2007-03-13T10:13:00","WFXW":"9088","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队海虞中队","CLSJ":"2007-03-13T10:16:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队海虞中队","HPHM":"苏EE8709","HPZL":"小型汽车","JDSBH":"320581031625520","JKRQ":"2007-03-13T10:16:00","WFDZ":"谢桥镇","WFJFS":0,"WFNR":"变更车道时影响正常行驶的机动车的","WFSJ":"2007-03-13T10:12:00","WFXW":"1043","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2006-08-29T00:00:00","FKJE":100,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EEF640","HPZL":"小型汽车","JDSBH":"320581051204028","JKRQ":"2006-08-29T00:00:00","WFDZ":"锁澜路","WFJFS":0,"WFSJ":"2006-08-23T15:19:00","WFXW":"9018","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队城区中队","CLSJ":"2006-07-12T10:17:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队城区中队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581031422345","JKRQ":"2006-07-12T10:17:00","WFDZ":"总马桥街","WFJFS":2,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2006-07-12T10:13:00","WFXW":"1207","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市城市巡逻警察大队","CLSJ":"2005-07-23T00:00:00","FKJE":200,"FLAG":0,"FXJGMC":"常熟市城市巡逻警察大队","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581011675830","JKRQ":"2005-07-23T00:00:00","WFDZ":"红旗南、北路","WFJFS":0,"WFNR":"驾驶未经检验合格的机动车","WFSJ":"2005-07-23T19:35:33","WFXW":"7002","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2005-02-25T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EB9044","HPZL":"小型汽车","JDSBH":"320581011703369","JKRQ":"2005-02-25T00:00:00","WFDZ":"205省道","WFJFS":3,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2005-02-25T17:42:00","WFXW":"13032","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟大队秩序科","CLSJ":"2005-02-08T00:00:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟大队秩序科","HPHM":"苏EB9044","HPZL":"小型汽车","JDSBH":"320581011703368","JKRQ":"2005-02-08T00:00:00","WFDZ":"205省道","WFJFS":3,"WFNR":"机动车行驶超过规定时速10%以上未达20%的","WFSJ":"2005-02-08T16:30:00","WFXW":"13032","XXLY":"现场处罚","ZT":"已交款"},{"CFZL":"罚款","CLJGMC":"常熟市交巡警大队警务通","CLSJ":"2004-08-25T09:35:00","FKJE":50,"FLAG":0,"FXJGMC":"常熟市交巡警大队警务通","HPHM":"苏EZ4595","HPZL":"普通摩托车","JDSBH":"320581031035778","JKRQ":"2004-08-25T09:35:00","WFDZ":"环城路","WFJFS":2,"WFNR":"驾驶摩托车时驾驶人未按规定戴安全头盔的","WFSJ":"2004-08-25T09:35:00","WFXW":"1207","XXLY":"现场处罚","ZT":"已交款"}]}
			tvs = TrafficVehicleService.getInstance();
			try{
				String info = tvs.getViolation(jszh, dabh);
				json =  JSONObject.parseObject(info);
				CacheBaseService.getInstance().cache(key,json,1f);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
//		String msg = (String)json.get("msg");
		//System.out.println("msg=="+msg);
		return json;
	}
	
	@RequestMapping(value = "{page}", method = RequestMethod.GET)
    public String gotoWxAPP(HttpServletRequest request,@PathVariable(value = "page")String page ) {
		String url = request.getRequestURI();
		System.out.println(url);
    	String wxecrytoken = request.getParameter("wxwebencrytoken");
    	System.out.println("wxwebencrytoken==="+wxecrytoken);
    	String name = request.getParameter("name");
    	System.out.println("name==="+name);
		return "wxapp/"+page;
    }
	
	
	
	@ResponseBody
	@RequestMapping(value = "testurl")
	public JSONObject testurl(HttpServletRequest request) {
		JSONArray jsonArray = new JSONArray();

		String sql = "select * from t_url_mark where safeurl is null";
		List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao
				.loadMapList(sql);
		for (Map<String, Object> map : list) {
			String localurl = (String) map.get("viewurl");
			String safeurl = SafeUrlUtils.GetSafeUrl(localurl,"szgawx");
			JSONObject json = new JSONObject();
			json.put("url", localurl);
			json.put("sence_id","szgawx");
			json.put("safeurl",safeurl);
			jsonArray.add(json);
			sql = "update t_url_mark set safeurl = ? where id = ?";
			commonDao.update(sql,safeurl,map.get("id"));
		}
		JSONObject result = new JSONObject();
    	result.put("res",jsonArray);
		return result;
    }

}
